﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

namespace RN.ERP.Web.Utilities
{
    public class KaoheRoleIDHelp
    {
        /// <summary>
        /// 取得考核角色列表。
        /// 企业登陆(企业：105)
        /// 市级主管（企业+自身：105,7173）
        /// 省级主管（全部：105,7173,7174）
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public static string GetRoleIds(string roleId)
        {
            string roleIds = string.Empty;
            ////企业
            if (ConfigurationManager.AppSettings["khrole0"] != null)
            {
                string khrole0= ConfigurationManager.AppSettings["khrole0"].ToString();
                roleIds += khrole0 + ","; 
            }
            ////市级
            string khrole1 = string.Empty;
            if (ConfigurationManager.AppSettings["khrole1"] != null)
            {
                khrole1= ConfigurationManager.AppSettings["khrole1"].ToString();
                if (khrole1.Split(',').Contains(roleId))
                {
                    roleIds += roleId + ","; 
                }
            }
            /////评审委员会
            string khrole3 = string.Empty;
            if (ConfigurationManager.AppSettings["khrole3"] != null)
            {
                khrole3 = ConfigurationManager.AppSettings["khrole3"].ToString();
                if (khrole3.Split(',').Contains(roleId))
                {
                    roleIds += roleId + ","; 
                }
            }
            ////省级
            if (ConfigurationManager.AppSettings["khrole2"] != null)
            {
                string khrole2 = ConfigurationManager.AppSettings["khrole2"].ToString();
                if (khrole2.Split(',').Contains(roleId))
                {
                    roleIds += roleId + ",";
                    if (!string.IsNullOrEmpty(khrole1))
                    {
                        roleIds += khrole1.TrimEnd(',') + ",";
                    }
                    if (!string.IsNullOrEmpty(khrole3))
                    {
                        roleIds += khrole3.TrimEnd(',') + ",";
                    }
                }
            }
            if (string.IsNullOrEmpty(roleIds))
            {
                roleIds = roleId;
            }
            return roleIds.TrimEnd(',');
        
        }

        /// <summary>
        /// 企业roleId
        /// </summary>
        public static string CorpRoleId
        {
            get
            {
                string roleId = string.Empty;
                ////企业
                if (ConfigurationManager.AppSettings["khrole0"] != null)
                {
                    roleId = ConfigurationManager.AppSettings["khrole0"].ToString();
                }
                return roleId;
            }
        }

        /// <summary>
        /// 市级roleId
        /// </summary>
        public static string CityRoleId
        {
            get
            {
                string roleId = string.Empty;
                ////企业
                if (ConfigurationManager.AppSettings["khrole1"] != null)
                {
                    roleId = ConfigurationManager.AppSettings["khrole1"].ToString();
                }
                return roleId;
            }
        }

        /// <summary>
        /// 省级roleId
        /// </summary>
        public static string ProvinceRoleId
        {
            get
            {
                string roleId = string.Empty;
                ////企业
                if (ConfigurationManager.AppSettings["khrole2"] != null)
                {
                    roleId = ConfigurationManager.AppSettings["khrole2"].ToString();
                }
                return roleId;
            }
        }
    }
}